package cookie;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/*
   会话技术:
     1:会话:一次会话中包含多次请求和响应.
         * 一次会话: 浏览器第一次给服务器资源发送请求,会话建立,直到有一方断开为止
     2:功能: 在一次会话的范围内的多次请求期间可以共享数据
     3:方式:
         1:客户端会话技术:Cookie
         2:服务器端会话技术: Session

  ## Cookie :
      1:概念: 客户端会话技术,将数据保存到客户端
      2:快速入门:
         步骤:  1:创建Cookie对象,并且绑定数据
                   * new Cookie(String name,String value)
               2:发送Cookie对象
                   * response.addCookie(Cookie cookie)
               3:获取Cookie,拿到数据
                   * request.getCookies()
*/


@WebServlet("/CookieDemo01")
public class CookieDemo01 extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
      //Cookie快速入门
        // 1 : 创建Cookie对象
        Cookie aa=new Cookie("msg","hihihihi");
        //2:发送Cookie
        resp.addCookie(aa);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }
}
